/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fait.ferm.persists;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Greg
 */
public class Equipment_staff extends PersistsObject {
    public int equipment_type_id;
    public int staff_type_id;
    public int quantity;
    
    public Equipment_staff(int pId) throws Exception {
        super(pId);
        table = "equipment_staff";
        load();
    }
    
    @Override
    public void load() throws Exception {
        boolean notSuccessfully=true;
		if(id==-1) {
			throw new Exception("Объект "+table+" отсутствует в базе");
		}	
		try (Statement st = con.createStatement()) {
			String q = "SELECT equipment_type_id, staff_type_id, quantity FROM "+table+" WHERE id = " + id;
			ResultSet rs = st.executeQuery(q);
			if(rs.next()){
				notSuccessfully=false;
                equipment_type_id = rs.getInt("equipment_type_id");
                staff_type_id = rs.getInt("staff_type_id");
				quantity = rs.getInt("quantity");
			}
			rs.close();
		}
		if(notSuccessfully) {
			throw new Exception("Объект "+table+" не загружен");
        }
    }

    @Override
    protected void update() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void createNew() throws SQLException, Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
